package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.OrderResult;
import cn.gson.crm.model.vo.SgfVO;
import cn.gson.crm.service.SgfService;

@Controller
public class SgfControl {
	@Autowired
	private SgfService service;

	@GetMapping("/toSgf")
	public String toSgf() {
		return "zj/sgf";
	}

	@GetMapping("/getAllSgf")
	@ResponseBody
	public Map getAllSgf(int page, int rows) {
		Map map = new HashMap<>();
		List<SgfVO> list = service.getAllSgf(page, rows);
		Long count = service.count();
		map.put("total", count);
		map.put("rows", list);
		return map;
	}
	
	@GetMapping("/deleteSgf")
	@ResponseBody
	public OrderResult deleteSgf(Long sgfId) {
		try {
			service.deleteSgf(sgfId);
			return new OrderResult();
		} catch (Exception e) {
			e.printStackTrace();
			return new OrderResult(e);
		}
	}
}
